/*
 * SoftwareSAR - 1.0
 */
package br.com.cpqd.ssar.gerenciador.gui;

import br.com.cpqd.ssar.gerenciador.GerenciamentoNucleo;
import br.com.cpqd.ssar.mediador.gui.*;
import br.com.cpqd.ssar.utilitarias.AtributosGeometria;
import br.com.cpqd.ssar.utilitarias.Cilindro;
import br.com.cpqd.ssar.utilitarias.Cone;
import br.com.cpqd.ssar.utilitarias.Esfera;
import br.com.cpqd.ssar.utilitarias.Geometria;
import br.com.cpqd.ssar.utilitarias.ListaGeometrias;
import br.com.cpqd.ssar.utilitarias.Material;
import br.com.cpqd.ssar.utilitarias.STL;
import br.com.cpqd.ssar.utilitarias.Tijolo;
import br.com.cpqd.ssar.utilitarias.Triangulo;
import java.awt.event.KeyEvent;

/**
 * Janela de Atribuição de Material
 * @author  Rafael Buck
 * @version 1.0
 */
public class JanelaPropriedades extends javax.swing.JDialog {

    /**
     * Controlador de Janelas
     */
    ControladorJanelas controladorJanelas;

    /**
     * Método Construtor
     * @param controladorJanelas ControladorJanelas
     * @param parent Frame
     * @param modal determina se a janela é modal ou não (impede o acesso as janelas abaixo)
     */
    public JanelaPropriedades(Object obj, GerenciamentoNucleo managementCore, java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        core = managementCore;
        objSelecionado = obj;
        lblAviso.setVisible(false);
        lblAvisoIcone.setVisible(false);

        /* Caso o Nó selecionado (selectedNode) for uma Geometria */
        if (objSelecionado instanceof Geometria) {

            /* Caracteristicas comum a todas as Geometrias */
            gAntes = (Geometria) objSelecionado;
            txtId.setText(String.valueOf(gAntes.getIdentificador()));
            txtNome.setText(gAntes.getNome());
            if (gAntes.getMaterial() != null) {
                txtMaterial.setText(String.valueOf(gAntes.getMaterial().getNome()));
            }
            material = gAntes.getMaterial();

            if (gAntes.getAtributos().getReferencial() != null) {
                float[] reference = new float[3];
                reference[0] = gAntes.getAtributos().getReferencial()[0];
                reference[1] = gAntes.getAtributos().getReferencial()[1];
                reference[2] = gAntes.getAtributos().getReferencial()[2];

                txtX.setText(String.valueOf(reference[0]));
                txtY.setText(String.valueOf(reference[1]));
                txtZ.setText(String.valueOf(reference[2]));
            }

            txtRotX.setText(String.valueOf(gAntes.getRotX()));
            txtRotY.setText(String.valueOf(gAntes.getRotY()));
            txtRotZ.setText(String.valueOf(gAntes.getRotZ()));

            if (gAntes.isVisible()) {
                chkVisivel.setSelected(true);
            } else {
                chkVisivel.setSelected(false);
            }

            if (gAntes.isSolid()) {
                chkSolido.setSelected(true);
            } else {
                chkSolido.setSelected(false);
            }


            /* Caracteristicas somente da Esfera */
            if (gAntes.getAtributos() instanceof Esfera) {
                txtAltura.setEditable(false);
                txtRaio.setText(String.valueOf(gAntes.getAtributos().getRaio()));

            /* Caracteristicas somente do Tijolo */
            } else if (gAntes.getAtributos() instanceof Tijolo) {
                txtAltura.setEditable(false);
                txtRaio.setEditable(false);

                txtX.setText(String.valueOf(gAntes.getAtributos().getFirsPoint()[0]));
                txtY.setText(String.valueOf(gAntes.getAtributos().getFirsPoint()[1]));
                txtZ.setText(String.valueOf(gAntes.getAtributos().getFirsPoint()[2]));

                txtXFinal.setEnabled(true);
                txtYFinal.setEnabled(true);
                txtZFinal.setEnabled(true);
                txtXFinal.setText(String.valueOf(gAntes.getAtributos().getSecondPoint()[0]));
                txtYFinal.setText(String.valueOf(gAntes.getAtributos().getSecondPoint()[1]));
                txtZFinal.setText(String.valueOf(gAntes.getAtributos().getSecondPoint()[2]));

            /* Caracteristicas somente do STL */
            } else if (gAntes.getAtributos() instanceof STL) {

                if (gAntes.getAtributos().getFirsPoint() == null) {

                    float[] ref = new float[3];
                    ref[0] = 0.0f;
                    ref[1] = 0.0f;
                    ref[2] = 0.0f;
                    gAntes.getAtributos().setReferencial(ref);

                    txtX.setText(String.valueOf(0.0));
                    txtY.setText(String.valueOf(0.0));
                    txtZ.setText(String.valueOf(0.0));
                    txtXFinal.setText(String.valueOf(0.0));
                    txtYFinal.setText(String.valueOf(0.0));
                    txtZFinal.setText(String.valueOf(0.0));

                } else {
                    txtX.setText(String.valueOf(gAntes.getAtributos().getFirsPoint()[0]));
                    txtY.setText(String.valueOf(gAntes.getAtributos().getFirsPoint()[1]));
                    txtZ.setText(String.valueOf(gAntes.getAtributos().getFirsPoint()[2]));

                    txtXFinal.setText(String.valueOf(gAntes.getAtributos().getSecondPoint()[0]));
                    txtYFinal.setText(String.valueOf(gAntes.getAtributos().getSecondPoint()[1]));
                    txtZFinal.setText(String.valueOf(gAntes.getAtributos().getSecondPoint()[2]));
                }

                txtXFinal.setEnabled(true);
                txtYFinal.setEnabled(true);
                txtZFinal.setEnabled(true);

                lblAviso.setVisible(true);
                lblAvisoIcone.setVisible(true);

                txtAltura.setEditable(false);
                txtRaio.setEditable(false);


            } else {
                txtAltura.setText(String.valueOf(gAntes.getAtributos().getAltura()));
                txtRaio.setText(String.valueOf(gAntes.getAtributos().getRaio()));
            }
        // caso não seja Geometria    
        } else {
            /* Caso o Nó selecionado (selectedNode) for uma ListaGeometrias */
            listG = (ListaGeometrias) objSelecionado;
            txtX.setEnabled(false);
            txtY.setEnabled(false);
            txtZ.setEnabled(false);
            txtAltura.setEnabled(false);
            txtRaio.setEnabled(false);
            txtXFinal.setEnabled(false);
            txtYFinal.setEnabled(false);
            txtZFinal.setEnabled(false);
            txtRotX.setEditable(false);
            txtRotY.setEditable(false);
            txtRotZ.setEditable(false);

            if (listG.getMaterial() != null) {
                txtMaterial.setText(listG.getMaterial().getNome());
            }
            txtId.setText(String.valueOf(listG.getId()));
            txtNome.setText(listG.getName());
            if (listG.isVisible()) {
                chkVisivel.setSelected(true);
            } else {
                chkVisivel.setSelected(false);
            }

            if (listG.isSolid()) {
                chkSolido.setSelected(true);
            } else {
                chkSolido.setSelected(false);
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        txtNome = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtId = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtZ = new javax.swing.JTextField();
        txtMaterial = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        txtAltura = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtY = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtX = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        btnConfirmar = new javax.swing.JButton();
        txtRaio = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        btnLimpar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnLocMaterial = new javax.swing.JButton();
        labelXFinal = new javax.swing.JLabel();
        txtXFinal = new javax.swing.JTextField();
        labelYFinal = new javax.swing.JLabel();
        txtYFinal = new javax.swing.JTextField();
        labelZFinal = new javax.swing.JLabel();
        txtZFinal = new javax.swing.JTextField();
        chkVisivel = new javax.swing.JCheckBox();
        chkSolido = new javax.swing.JCheckBox();
        labelXFinal1 = new javax.swing.JLabel();
        labelYFinal1 = new javax.swing.JLabel();
        labelZFinal1 = new javax.swing.JLabel();
        txtRotZ = new javax.swing.JTextField();
        txtRotY = new javax.swing.JTextField();
        txtRotX = new javax.swing.JTextField();
        lblAviso = new javax.swing.JLabel();
        lblAvisoIcone = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Editar Propriedades");
        setLocationByPlatform(true);
        setModal(true);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(231, 240, 250));

        txtNome.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        txtNome.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNomeenter(evt);
            }
        });

        jLabel6.setText("Y:");

        txtId.setEditable(false);
        txtId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdActionPerformed(evt);
            }
        });

        jLabel9.setText("Raio:");

        jLabel8.setText("Altura:");

        txtZ.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        txtZ.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtZenter(evt);
            }
        });

        txtMaterial.setEditable(false);
        txtMaterial.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        txtAltura.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        txtAltura.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtAlturaenter(evt);
            }
        });

        jLabel2.setText("Nome:");

        txtY.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        txtY.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtYenter(evt);
            }
        });

        jLabel7.setText("Z:");

        txtX.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        txtX.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtXenter(evt);
            }
        });

        jLabel5.setText("X:");

        jLabel1.setText("Id:");

        btnConfirmar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/confirmar.png"))); // NOI18N
        btnConfirmar.setText("Confirmar");
        btnConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConfirmarActionPerformed(evt);
            }
        });

        txtRaio.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        txtRaio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtRaioenter(evt);
            }
        });

        jLabel3.setText("Material:");

        btnLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/limpar1.png"))); // NOI18N
        btnLimpar.setText("Limpar");
        btnLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/Cancelar.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnLocMaterial.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/folder_explore.png"))); // NOI18N
        btnLocMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLocMaterialActionPerformed(evt);
            }
        });

        labelXFinal.setText("Xf:");

        txtXFinal.setEnabled(false);
        txtXFinal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtXFinalKeyPressed(evt);
            }
        });

        labelYFinal.setText("Yf:");

        txtYFinal.setEnabled(false);
        txtYFinal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtYFinalKeyPressed(evt);
            }
        });

        labelZFinal.setText("Zf:");

        txtZFinal.setEnabled(false);
        txtZFinal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtZFinalKeyPressed(evt);
            }
        });

        chkVisivel.setBackground(new java.awt.Color(231, 240, 250));
        chkVisivel.setText("Visível");

        chkSolido.setBackground(new java.awt.Color(231, 240, 250));
        chkSolido.setText("Sólido");

        labelXFinal1.setText("Rotação em X:");

        labelYFinal1.setText("Rotação em Y:");

        labelZFinal1.setText("Rotação em Z:");

        txtRotZ.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtRotZKeyPressed(evt);
            }
        });

        txtRotY.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtRotYKeyPressed(evt);
            }
        });

        txtRotX.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtRotXKeyPressed(evt);
            }
        });

        lblAviso.setForeground(new java.awt.Color(255, 51, 51));
        lblAviso.setText("Arquivos STL não possuem referência...");
        lblAviso.setToolTipText("A cada \"Confirmar\" os valores de X, Y, Z e Rotações serão aplicados");
        lblAviso.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(255, 102, 102)));

        lblAvisoIcone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/warning.gif"))); // NOI18N
        lblAvisoIcone.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(255, 102, 102)));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel1)
                                                    .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel2)))
                                            .addComponent(jLabel3))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel9)
                                            .addComponent(jLabel5)
                                            .addComponent(jLabel6)
                                            .addComponent(jLabel7))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtY, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtX, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(txtRaio)
                                                .addComponent(txtZ, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(txtMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(14, 14, 14)
                                        .addComponent(btnLocMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addComponent(labelZFinal)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(txtZFinal))
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(labelXFinal)
                                                .addComponent(labelYFinal))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(txtYFinal)
                                                .addComponent(txtXFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(labelZFinal1)
                                            .addComponent(jLabel8)
                                            .addComponent(labelYFinal1)
                                            .addComponent(labelXFinal1))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtRotX, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtAltura, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtRotY, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                                            .addComponent(txtRotZ, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)))))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(chkVisivel)
                                .addGap(18, 18, 18)
                                .addComponent(chkSolido))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lblAvisoIcone, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblAviso, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 238, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(273, Short.MAX_VALUE)
                        .addComponent(btnConfirmar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnLimpar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancelar)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelXFinal)
                            .addComponent(txtXFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtYFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelYFinal))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtZFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelZFinal)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2))
                                .addGap(3, 3, 3)
                                .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(55, 55, 55)
                        .addComponent(jLabel3))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtZ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(txtRaio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(txtAltura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(txtMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnLocMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelXFinal1)
                            .addComponent(txtRotX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(35, 35, 35)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtRotY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelYFinal1))
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtRotZ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelZFinal1))
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chkVisivel)
                    .addComponent(chkSolido))
                .addGap(41, 41, 41)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblAviso, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAvisoIcone, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnLimpar)
                    .addComponent(btnConfirmar))
                .addGap(19, 19, 19))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void txtNomeenter(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNomeenter
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtNomeenter

private void txtIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIdActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtIdActionPerformed

private void txtZenter(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtZenter
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtZenter

    public boolean isConfirmed() {
        return alterado;
    }

    public Object getObjAlterado() {
        return objSelecionado;
    }

private void txtAlturaenter(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtAlturaenter
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtAlturaenter

private void txtYenter(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtYenter
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtYenter

private void txtXenter(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtXenter
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtXenter

private void btnConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfirmarActionPerformed
// TODO add your handling code here:

    if (objSelecionado instanceof Geometria) {

        alterado = true;


        if (    (txtRotX.getText().contains(String.valueOf(gAntes.getRotX())))
                && (txtRotY.getText().contains(String.valueOf(gAntes.getRotY())))
                && (txtRotZ.getText().contains(String.valueOf(gAntes.getRotZ()))) ) {
            alteradoRotacao = false;
            System.out.println("x igual");
        }
        

        if (txtRotX.getText().isEmpty()) {

            core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Rotação em X:\" ");
            txtRotX.requestFocus();
            alterado = false;
        }

        if (txtRotY.getText().isEmpty()) {
            core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Rotação em Y:\" ");
            txtRotY.requestFocus();
            alterado = false;
        }
        if (txtRotZ.getText().isEmpty()) {
            core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Rotação em Z:\" ");
            txtRotZ.requestFocus();
            alterado = false;
        }

        float reference[] = new float[3];

        if (txtX.getText().isEmpty()) {
            core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"X:\" ");
            txtX.requestFocus();
            alterado = false;
        } else {
            reference[0] = Float.parseFloat(txtX.getText());
            System.out.println("referencia x: " + reference[0]);
        }

        if (txtY.getText().isEmpty()) {
            core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Y:\" ");
            txtY.requestFocus();
            alterado = false;
        } else {
            reference[1] = Float.parseFloat(txtY.getText());
            System.out.println("referencia y: " + reference[1]);
        }
        if (txtZ.getText().isEmpty()) {
            core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Z:\" ");
            txtZ.requestFocus();
            alterado = false;
        } else {
            reference[2] = Float.parseFloat(txtZ.getText());
            System.out.println("referencia z: " + reference[2]);
        }

        if (txtNome.getText().isEmpty()) {
            core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Nome:\" ");
            txtNome.requestFocus();
            alterado = false;
        }

        if (gAntes.getAtributos() instanceof Esfera) {

            if (txtRaio.getText().isEmpty()) {

                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Raio:\" ");
                txtRaio.requestFocus();
                alterado = false;

            }

            if (alterado) {

                Material mTemp = null;
                if (material != null) {
                    mTemp = material;
                }

                AtributosGeometria atributos = new Esfera(Float.parseFloat(txtRaio.getText()), reference, 2);

                gDepois = new Geometria(Integer.valueOf(txtId.getText()), txtNome.getText(), atributos, chkVisivel.isSelected(), chkSolido.isSelected(), mTemp, Float.parseFloat(txtRotX.getText()), Float.parseFloat(txtRotY.getText()), Float.parseFloat(txtRotZ.getText()));

                if (core.verificaLimiteComputacional(gDepois)) {

                    gAntes.setNome(gDepois.getNome());
                    gAntes.setAtributos(gDepois.getAtributos());
                    gAntes.setMaterial(gDepois.getMaterial());
                    gAntes.setSolid(gDepois.isSolid());
                    gAntes.setVisible(gDepois.isVisible());
                    gAntes.setRotX(gDepois.getRotX());
                    gAntes.setRotY(gDepois.getRotY());
                    gAntes.setRotZ(gDepois.getRotZ());
                    gAntes.setListaTriangulos(gAntes.getAtributos().triangularizarGeometria());
                    
                    if (alteradoRotacao)
                    {
                        gAntes.rotacionar();                     
                        alterado = true;
                        
                    
                    } else {

                        objSelecionado = gAntes;
                        alterado = false;
                        
                        dispose();
                    }
                }

                else
                {
                    core.getInterfaceServicos().exibirMensagemAlerta("Geometria fora do domínio de simulação");
                }
            }
        }

        if (gAntes.getAtributos() instanceof Tijolo) {

            float[] firstPoint = new float[3];
            float[] secondPoint = new float[3];
            firstPoint = reference;

            if (txtXFinal.getText().isEmpty()) {
                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Xf:\" ");
                txtXFinal.requestFocus();
                alterado = false;
            } else {
                secondPoint[0] = Float.parseFloat(txtXFinal.getText());
            }

            if (txtYFinal.getText().isEmpty()) {
                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Yf:\" ");
                txtYFinal.requestFocus();
                alterado = false;
            } else {
                secondPoint[1] = Float.parseFloat(txtYFinal.getText());
            }
            if (txtZFinal.getText().isEmpty()) {
                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Zf:\" ");
                txtZFinal.requestFocus();
                alterado = false;
            } else {
                secondPoint[2] = Float.parseFloat(txtZFinal.getText());
            }


            if (alterado) {

                AtributosGeometria atributos = new Tijolo(firstPoint, secondPoint, reference, 1);
                Material mTemp = null;
                if (material != null) {
                    mTemp = material;
                }

                gDepois = new Geometria(Integer.valueOf(txtId.getText()), txtNome.getText(), atributos, chkVisivel.isSelected(), chkSolido.isSelected(), mTemp, Float.parseFloat(txtRotX.getText()), Float.parseFloat(txtRotY.getText()), Float.parseFloat(txtRotZ.getText()));

                if (core.verificaLimiteComputacional(gDepois)) {

                    gAntes.setNome(gDepois.getNome());
                    gAntes.setAtributos(gDepois.getAtributos());
                    gAntes.setMaterial(gDepois.getMaterial());
                    gAntes.setSolid(gDepois.isSolid());
                    gAntes.setVisible(gDepois.isVisible());
                    gAntes.setRotX(gDepois.getRotX());
                    gAntes.setRotY(gDepois.getRotY());
                    gAntes.setRotZ(gDepois.getRotZ());
                    gAntes.setListaTriangulos(gAntes.getAtributos().triangularizarGeometria());
                    if (alteradoRotacao) {
                        gAntes.rotacionar();
                    }
                    alterado = true;
                    dispose();
                } else {

                    objSelecionado = gAntes;
                    alterado = false;
                    core.getInterfaceServicos().exibirMensagemAlerta("Geometria fora do domínio de simulação");

                }
            }

        }
        if (gAntes.getAtributos() instanceof STL) {

            float[] firstPoint = new float[3];
            float[] secondPoint = new float[3];

            if (txtX.getText().isEmpty()) {
                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"X:\" ");
                txtX.requestFocus();
                alterado = false;
            } else {
                firstPoint[0] = Float.parseFloat(txtX.getText());
            }

            if (txtY.getText().isEmpty()) {
                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Y:\" ");
                txtY.requestFocus();
                alterado = false;
            } else {
                firstPoint[1] = Float.parseFloat(txtY.getText());
            }

            if (txtZ.getText().isEmpty()) {
                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Z:\" ");
                txtZ.requestFocus();
                alterado = false;
            } else {
                firstPoint[2] = Float.parseFloat(txtZ.getText());
            }

            if (txtXFinal.getText().isEmpty()) {
                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Xf:\" ");
                txtXFinal.requestFocus();
                alterado = false;
            } else {
                secondPoint[0] = Float.parseFloat(txtXFinal.getText());
            }

            if (txtYFinal.getText().isEmpty()) {
                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Yf:\" ");
                txtYFinal.requestFocus();
                alterado = false;
            } else {
                secondPoint[1] = Float.parseFloat(txtYFinal.getText());
            }
            if (txtZFinal.getText().isEmpty()) {
                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Zf:\" ");
                txtZFinal.requestFocus();
                alterado = false;
            } else {
                secondPoint[2] = Float.parseFloat(txtZFinal.getText());
            }


            if (alterado) {

                gAntes = (Geometria) objSelecionado;
                gDepois = core.copiarGeometria(gAntes);
                gDepois.getAtributos().redimensionarSTL(firstPoint, secondPoint);
                gDepois.setListaTriangulos(gDepois.getAtributos().triangularizarGeometria());

                if (core.verificaLimiteComputacional(gDepois)) {

                    gAntes.setNome(txtNome.getText());
                    //gAntes.getAtributos().setReferencial(reference);
                    gAntes.setVisible(chkVisivel.isSelected());
                    gAntes.setSolid(chkSolido.isSelected());
                    if (material != null) {
                        gAntes.setMaterial(material);
                    }
                    gAntes.getAtributos().redimensionarSTL(firstPoint, secondPoint);

                    gAntes.setRotX(Float.parseFloat(txtRotX.getText()));
                    gAntes.setRotY(Float.parseFloat(txtRotY.getText()));
                    gAntes.setRotZ(Float.parseFloat(txtRotZ.getText()));


                    gAntes.setListaTriangulos(gAntes.getAtributos().triangularizarGeometria());
                    if (alteradoRotacao) {
                        gAntes.rotacionar();
                    }
                    gAntes.getAtributos().addX(Float.parseFloat(txtX.getText()));
                    gAntes.getAtributos().addY(Float.parseFloat(txtY.getText()));
                    gAntes.getAtributos().addY(Float.parseFloat(txtY.getText()));
                    objSelecionado = gAntes;
                    alterado = true;
                    //lblAviso.setVisible(false);
                    //lblAvisoIcone.setVisible(false);
                    dispose();



                } else {

                    objSelecionado = gAntes;
                    alterado = false;
                    core.getInterfaceServicos().exibirMensagemAlerta("Geometria fora do domínio de simulação");
                }
            }
        }

        if (gAntes.getAtributos() instanceof Cone) {

            if (txtRaio.getText().isEmpty()) {

                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Raio:\" ");
                txtRaio.requestFocus();
                alterado = false;

            }

            if (txtAltura.getText().isEmpty()) {

                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Altura:\" ");
                txtAltura.requestFocus();
                alterado = false;

            }

            if (alterado) {

                AtributosGeometria atributos = new Cone(Float.parseFloat(txtRaio.getText()), Float.parseFloat(txtAltura.getText()), reference, 4);
                Material mTemp = null;
                if (material != null) {
                    mTemp = material;
                }
                gDepois = new Geometria(Integer.valueOf(txtId.getText()), txtNome.getText(), atributos, chkVisivel.isSelected(), chkSolido.isSelected(), mTemp, Float.parseFloat(txtRotX.getText()), Float.parseFloat(txtRotY.getText()), Float.parseFloat(txtRotZ.getText()));

                if (core.verificaLimiteComputacional(gDepois)) {

                    gAntes.setNome(gDepois.getNome());
                    gAntes.setAtributos(gDepois.getAtributos());
                    gAntes.setMaterial(gDepois.getMaterial());
                    gAntes.setSolid(gDepois.isSolid());
                    gAntes.setVisible(gDepois.isVisible());
                    gAntes.setRotX(gDepois.getRotX());
                    gAntes.setRotY(gDepois.getRotY());
                    gAntes.setRotZ(gDepois.getRotZ());
                    gAntes.setListaTriangulos(gAntes.getAtributos().triangularizarGeometria());
                    if (alteradoRotacao) {
                        gAntes.rotacionar();

                    }
                    alterado = true;

                } else {

                    objSelecionado = gAntes;
                    alterado = false;
                    core.getInterfaceServicos().exibirMensagemAlerta("Geometria fora do domínio de simulação)");

                }
            }
        }

        if (gAntes.getAtributos() instanceof Cilindro) {

            if (txtRaio.getText().isEmpty()) {

                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Raio:\" ");
                txtRaio.requestFocus();
                alterado = false;

            }
            if (txtAltura.getText().isEmpty()) {

                core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Raio:\" ");
                txtAltura.requestFocus();
                alterado = false;

            }

            if (alterado) {

                AtributosGeometria atributos = new Cilindro(Float.parseFloat(txtRaio.getText()), Float.parseFloat(txtAltura.getText()), reference, 4);
                Material mTemp = null;
                if (material != null) {
                    mTemp = material;
                }
                gDepois = new Geometria(Integer.valueOf(txtId.getText()), txtNome.getText(), atributos, chkVisivel.isSelected(), chkSolido.isSelected(), mTemp, Float.parseFloat(txtRotX.getText()), Float.parseFloat(txtRotY.getText()), Float.parseFloat(txtRotZ.getText()));

                if (core.verificaLimiteComputacional(gDepois)) {

                    gAntes.setNome(gDepois.getNome());
                    gAntes.setAtributos(gDepois.getAtributos());
                    gAntes.setMaterial(gDepois.getMaterial());
                    gAntes.setSolid(gDepois.isSolid());
                    gAntes.setVisible(gDepois.isVisible());
                    gAntes.setRotX(gDepois.getRotX());
                    gAntes.setRotY(gDepois.getRotY());
                    gAntes.setRotZ(gDepois.getRotZ());
                    gAntes.setListaTriangulos(gAntes.getAtributos().triangularizarGeometria());
                    if (alteradoRotacao) {
                        gAntes.rotacionar();
                        System.out.println("cilindro rotacionado");
                    }
                    alterado = true;

                } else {

                    objSelecionado = gAntes;
                    alterado = false;
                    core.getInterfaceServicos().exibirMensagemAlerta("Geometria fora do domínio de simulação");

                }
            }
        }
    } //fim Geometria




    if (objSelecionado instanceof ListaGeometrias) {

        if (txtNome.getText().isEmpty()) {
            core.getInterfaceServicos().exibirMensagemAlerta("Preencha o campo \"Nome\". ");
            txtNome.requestFocus();
            alterado = false;
        } else {
            listG.setName(txtNome.getText());
            alterado = true;
        }

        if (alterado) {
            if (material != null) {
                listG.setMaterialGrupo(material);
            }

            listG.setGroupSolid(chkSolido.isSelected());
            listG.setGroupVisible(chkVisivel.isSelected());
            objSelecionado = listG;
            alterado = true;

        }
    }

    if (alterado) {
//        gAntes.rotacionar();
        dispose();
    }



}//GEN-LAST:event_btnConfirmarActionPerformed

private void txtRaioenter(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRaioenter
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtRaioenter

private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparActionPerformed
// TODO add your handling code here:
    txtNome.setText("");
    txtX.setText("");
    txtY.setText("");
    txtZ.setText("");
    txtXFinal.setText("");
    txtYFinal.setText("");
    txtZFinal.setText("");
    txtRaio.setText("");
    txtAltura.setText("");
    txtRotX.setText("");
    txtRotY.setText("");
    txtRotZ.setText("");
}//GEN-LAST:event_btnLimparActionPerformed

private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
// TODO add your handling code here:
    alterado = true;
    dispose();
}//GEN-LAST:event_btnCancelarActionPerformed

private void btnLocMaterialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLocMaterialActionPerformed
// TODO add your handling code here:

    material = core.getInterfaceServicos().setMaterial();
    if (material != null) {
        txtMaterial.setText(material.getNome());
    }
}//GEN-LAST:event_btnLocMaterialActionPerformed

private void txtRotXKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRotXKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtRotXKeyPressed

private void txtRotYKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRotYKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtRotYKeyPressed

private void txtRotZKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRotZKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtRotZKeyPressed

private void txtXFinalKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtXFinalKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtXFinalKeyPressed

private void txtYFinalKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtYFinalKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtYFinalKeyPressed

private void txtZFinalKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtZFinalKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        System.out.println("enter");
        btnConfirmar.doClick();
    }
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.out.println("esc");
        btnCancelar.doClick();
    }
}//GEN-LAST:event_txtZFinalKeyPressed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnConfirmar;
    private javax.swing.JButton btnLimpar;
    private javax.swing.JButton btnLocMaterial;
    private javax.swing.JCheckBox chkSolido;
    private javax.swing.JCheckBox chkVisivel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel labelXFinal;
    private javax.swing.JLabel labelXFinal1;
    private javax.swing.JLabel labelYFinal;
    private javax.swing.JLabel labelYFinal1;
    private javax.swing.JLabel labelZFinal;
    private javax.swing.JLabel labelZFinal1;
    private javax.swing.JLabel lblAviso;
    private javax.swing.JLabel lblAvisoIcone;
    private javax.swing.JTextField txtAltura;
    private javax.swing.JTextField txtId;
    private javax.swing.JTextField txtMaterial;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtRaio;
    private javax.swing.JTextField txtRotX;
    private javax.swing.JTextField txtRotY;
    private javax.swing.JTextField txtRotZ;
    private javax.swing.JTextField txtX;
    private javax.swing.JTextField txtXFinal;
    private javax.swing.JTextField txtY;
    private javax.swing.JTextField txtYFinal;
    private javax.swing.JTextField txtZ;
    private javax.swing.JTextField txtZFinal;
    // End of variables declaration//GEN-END:variables
    private Object objSelecionado;
    private Geometria gAntes;
    private Geometria gDepois;
    ListaGeometrias listG;
    private boolean alterado;
    private boolean alteradoRotacao = true;
    private Material material = null;
    private GerenciamentoNucleo core;
}

